<?php
declare (strict_types = 1);

namespace app\controller;

use app\BaseController;
use app\model\Opinion;
use app\model\OpinionClass;
use app\Request;

class OpinionController extends BaseController
{
	protected $middleware = ['Login' => ['except' => ['class']]];
	
	function class()
	{
		$rows = OpinionClass::order(['weigh'=>'desc'])->select();
		$this->writeJson($rows);
	}
	
	/**
	 * 反馈
	 * @param Request $request
	 * @return void
	 */
	function save(Request $request)
	{
		$class_id = $request->post('class_id/d');
		$content = $request->post('content');
		$images = $request->post('images');
		$name = $request->post('name');
		$mobile = $request->post('mobile');
		Opinion::create([
			'class_id'=>$class_id,
			'user_id'=>$this->user_id,
			'content'=>$content,
			'images'=>$images,
			'name'=>$name,
			'mobile'=>$mobile,
		]);
		$this->writeJson();
	}
}
